#include "keypressfilter.h"
#include <QKeyEvent>
#include <QListView>
#include <QDebug>

KeyPressFilter::KeyPressFilter(QObject *parent) :
    QObject(parent)
{
}

bool KeyPressFilter::eventFilter(QObject *obj, QEvent *event){
	if (event->type() == QEvent::KeyPress) {
		QKeyEvent *keyEvent = static_cast<QKeyEvent *>(event);
		if( keyEvent->key() == Qt::Key_Return ){
			QListView *list = dynamic_cast<QListView*>(obj);
			if( list ){
				emit enterPressed(list->currentIndex());
				return true;
			}
		}
	}

	// standard event processing
	return QObject::eventFilter(obj, event);
}
